from messAround.model.acfun import AcFunRankModel, AcfunSearchModel
import messAround.util.help as util


# A站排行榜
class AcFunRankPipeline(object):

    @staticmethod
    def process_item(item, spider):
        return util.make_write_data({
            'nav_channel_id': int(item["nav_channel_id"]),
            'channel_id': int(item["channel_id"]),
            'channel_name': item["channel_name"],
            'title': item["title"],
            'info': item["info"],
            'cover': item["cover"],
            'video': "https://www.acfun.cn/v/" + item["video_id"],
            'video_id': int(item["video_id"]),
            'video_duration': int(item["video_duration"]),
            'mobile': item["mobile_link"],
            'play_count': int(item["play_count"]),
            'danmaku_count': int(item["danmaku_count"]),
            'share_count': int(item["share_count"]),
            'author_id': int(item["author_id"]),
            'author_name': item["author_name"],
            'author_fans': int(item["author_fans_count"]),
            'author_avatar': item["author_avatar"],
            'author_signature': item["author_signature"],
        }, item, AcFunRankModel)


# A站热搜
class AcfunSearchPipeline(object):

    @staticmethod
    def process_item(item, spider):
        return util.make_write_data({
            'link': item["link"],
            'keyword': item["keyword"],
        }, item, AcfunSearchModel)
